﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace zlh
{
    public partial class _default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {


        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RadioButtonList1.SelectedValue == "管理员")
            {
                MultiView1.ActiveViewIndex = 0;
            }
            else if (RadioButtonList1.SelectedValue == "学生")
            {
                MultiView1.ActiveViewIndex = 1;
            }
            else if (RadioButtonList1.SelectedValue == "班干")
            {
                MultiView1.ActiveViewIndex = 2;
            }
            else if (RadioButtonList1.SelectedValue == "教师")
            {
                MultiView1.ActiveViewIndex = 3;
            }
        }

        protected void AdminBtn2_Click(object sender, EventArgs e)
        {
            adminName.Text = "";
            AdminPSW.Text = "";
        }

        protected void StuBtn2_Click(object sender, EventArgs e)
        {
            StuId.Text = "";
            StuPSW.Text = "";
        }

        protected void fuBtn2_Click(object sender, EventArgs e)
        {
            fuName.Text = "";
            fuPSW.Text = "";
        }

        protected void teabtn2_Click(object sender, EventArgs e)
        {
            tea.Text = "";
            teaPSW.Text = "";            
        }

        protected void AdminBtn_Click(object sender, EventArgs e)
        {
                string Admin = this.adminName.Text;
                string pwd = this.AdminPSW.Text; ;
                //string sql = "SELECT  * FROM AdminLogin WHERE adminName='" + Admin + "'";
                string sql = "SELECT  * FROM AdminLogin WHERE adminName='" + this.adminName.Text + "'and adminPassword='" + this.AdminPSW.Text + "'";
                SqlParameter[] parameters = 
                {
                   new SqlParameter("@adminName",Admin),
                   new SqlParameter("@adminPassword",pwd)
                };
                SqlDataReader sdr = SqlHelper.ExecuteReader(sql, parameters);
                if (sdr.Read())
                {
                    Session["Admin"]= sdr["adminName"].ToString();
                    Session["pwd"] = sdr["adminPassword"].ToString();
                    if (adminName.Text == Session["Admin"].ToString() && AdminPSW.Text == Session["pwd"].ToString()) 
                    {
                        sdr.Close();
                    }                    
                    if (Session["CheckCode"] != null)
                    {
                        string checkcode = Session["CheckCode"].ToString();
                        if (this.admintxtVerify.Text == checkcode)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入正确!')", true);
                            Response.Redirect("~/Adminyemian/adminshouye.aspx");
                            Session["Adminlbl"] = this.adminName.Text;
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true);
                        }
                    }

                }
                else
                {
                    sdr.Close();
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loginError", "alert('用户或密码错误！');", true);
                }
            }
           

        protected void StuBtn_Click(object sender, EventArgs e)
        {
                string student = this.StuId.Text;
                string stupwd = this.StuPSW.Text; ;
                string sql = "SELECT  * FROM StudentLogin WHERE StudentId='" + this.StuId.Text + "'and StudentPassword='" + this.StuPSW.Text + "'";
                SqlParameter[] parameters = 
                {
                   new SqlParameter("@StudentId",student),
                   new SqlParameter("@StudentPassword",stupwd)
                };
                SqlDataReader sdr = SqlHelper.ExecuteReader(sql, parameters);
                if (sdr.Read())
                {
                    Session["student"] = sdr["StudentId"].ToString();
                    Session["stupwd"] = sdr["StudentPassword"].ToString();
                    if (StuId.Text == Session["student"].ToString() && StuPSW.Text == Session["stupwd"].ToString())
                    {
                        sdr.Close();
                    }                     
                    if (Session["CheckCode"] != null)
                    {
                        string checkcode = Session["CheckCode"].ToString();
                        if (this.stutxtVerify.Text == checkcode)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入正确!')", true);
                            Response.Redirect("~/Studentyemian/stushouye.aspx");
                            Session["student"] = this.StuId.Text;
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true);
                        }
                    }

                }
                else
                {
                    sdr.Close();
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loginError", "alert('用户或密码错误！');", true);
                }
            }
          
        protected void fuBtn_Click(object sender, EventArgs e)
        {
            string bangan = this.fuName.Text;
            string banganpwd = this.fuPSW.Text; ;
            string sql = "SELECT  * FROM fuLogin WHERE fuId='" + this.fuName.Text + "'and fuPassword='" + this.fuPSW.Text + "'";
                SqlParameter[] parameters = 
                {
                   new SqlParameter("@fuId",bangan),
                   new SqlParameter("@fuPassword",banganpwd)
                };
                SqlDataReader sdr = SqlHelper.ExecuteReader(sql, parameters);
                if (sdr.Read())
                {
                    Session["bangan"] = sdr["fuId"].ToString();
                    Session["banganpwd"] = sdr["fuPassword"].ToString();
                    if (fuName.Text == Session["bangan"].ToString() && fuPSW.Text == Session["banganpwd"].ToString())
                    {
                        sdr.Close();
                    } 
                    if (Session["CheckCode"] != null)
                    {
                        string checkcode = Session["CheckCode"].ToString();
                        if (this.futxtVerify.Text == checkcode)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入正确!')", true);
                            Response.Redirect("~/banganyemian/banshouye.aspx");
                            Session["bangan"] = this.fuName.Text;
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true);
                        }
                    }

                }
                else
                {
                    sdr.Close();
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loginError", "alert('用户或密码错误！');", true);
                }
          }
            
       

        protected void teabtn_Click(object sender, EventArgs e)
        {
            string teacher = this.tea.Text;
            string teacherpwd = this.teaPSW.Text; ;
            string sql = "SELECT  * FROM TeacherLogin WHERE TeaId='" + this.tea.Text + "'and TeaPassword='" + this.teaPSW.Text + "'";
            SqlParameter[] parameters = 
                {
                   new SqlParameter("@TeaId",teacher),
                   new SqlParameter("@TeaPassword",teacherpwd)
                };
            SqlDataReader sdr = SqlHelper.ExecuteReader(sql, parameters);
            if (sdr.Read())
            {
                Session["teacher"] = sdr["TeaId"].ToString();
                Session["teacherpwd"] = sdr["TeaPassword"].ToString();
                if (tea.Text == Session["teacher"].ToString() && teaPSW.Text == Session["teacherpwd"].ToString())
                {
                    sdr.Close();
                } 
                if (Session["CheckCode"] != null)
                {
                    string checkcode = Session["CheckCode"].ToString();
                    if (this.teatxtVerify.Text == checkcode)
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入正确!')", true);
                        Response.Redirect("~/teacheryemian/teaxueshengxinxichaxun.aspx");
                        Session["teacher"] = this.tea.Text;
                    }
                    else
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true);
                    }
                }

            }
            else
            {
                sdr.Close();
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loginError", "alert('用户或密码错误！');", true);
            }
        }

        protected void RegStu2_Click(object sender, EventArgs e)
        {
            tea.Text = "";
            teaPSW.Text = "";
        }
    }
}